$(function () {
    var ue = UE.getEditor('container', {
        'serverUrl': '/ueditor/upload/'
    });

    $("#save-post-btn").click(function (event) {
        event.preventDefault();
        var titleInput = $("input[name='title']");
        var boardSelect = $("select[name='board_id']");


        var title = titleInput.val();
        var board_id = boardSelect.val();
        var context = ue.getContent();
        console.log(board_id)
        zlajax.post({
            "url": "/front/apost/",
            "data": {
                "title": title,
                "context": context,
                "board_id": board_id
            },
            "success": function (data) {
                if (data["code"] == 200) {
                    xtalert.alertConfirm({
                        "msg": "恭喜！发表成功",
                        "cancelText": "返回首页",
                        "confirmText": "再发一篇",
                        "cancelCallback":function () {
                            window.location = "/front/";
                        },
                        "confirmCallback":function () {
                            titleInput.val("");
                            ue.setContent('');
                        }
                    })
                }else{
                    xtalert.alertErrorToast(data["message"]);
                }
            }
        })
    })
})